package cz.muni.fi.pa165.musiclibrary.impl.service.dto.translator;

import org.apache.commons.lang3.Validate;

import cz.muni.fi.pa165.musiclibrary.impl.database.entity.IAlbum;
import cz.muni.fi.pa165.musiclibrary.api.service.dto.IAlbumDTO;
import cz.muni.fi.pa165.musiclibrary.impl.database.entity.Album;
import cz.muni.fi.pa165.musiclibrary.impl.service.dto.AlbumDTO;

/**
* Class with static methods for translating between {@link IAlbum} 
* and {@link IAlbumDTO} objects.
* 
* @author Radoslav Stefanik 
* 2012-10-28T16:10:43+0100
*/
public final class AlbumDTOTranslator {
    
    /**
     * Translates {@link IAlbum} object into {@link IAlbumDTO} object.
     * @param album Album.
     * @return Instance of {@link IAlbumDTO} that correspons with given parameter.
     */
    public static IAlbumDTO translateToDTO(IAlbum album) {
        if (album == null) {
            return null;
        }
        IAlbumDTO albumDTO = new AlbumDTO();
        albumDTO.setIdAlbum(album.getIdAlbum());
        albumDTO.setTitle(album.getTitle());
        albumDTO.setReleaseDate(album.getReleaseDate());
        albumDTO.setAlbumArt(album.getAlbumArt());
        return albumDTO;
    }
        
    /**
     * Translates {@link IAlbumDTO} object into {@link IAlbum} object.
     * @param album AlbumDTO.
     * @return Instance of {@link IAlbum} that correspons with given parameter.
     * @throws IllegalArgumentException If parameter is {@code null}.
     */
    public static IAlbum translateFromDTO(IAlbumDTO albumDTO) {
        Validate.isTrue(albumDTO != null, "AlbumDTO should not be null.");
        IAlbum album = new Album();
        if(albumDTO.getIdAlbum()!=null) {
            album.setIdAlbum(albumDTO.getIdAlbum());
        }
        album.setTitle(albumDTO.getTitle());
        album.setReleaseDate(albumDTO.getReleaseDate());
        album.setAlbumArt(albumDTO.getAlbumArt());
        return album;
    }
}